import java.util.InputMismatchException;
public class GuessNumber {
    public static void main(String [] args) {
        System.out.println("欢迎来到猜数字！");
        while(true) {
            int answer = (int)(Math.random()*100 + 1);
            System.out.println(answer);
            Scanner scan = new Scanner(System.in);
            int chances = 7;
            while(chances > 0) {
                System.out.println("请猜⼀个1-100之间的整数，含1和100，你还有" +
                        chances + "次机会：");
                int guess = scan.nextInt();
                if (guess > answer) {
                    System.out.println("⼤了！");
                } else if (guess < answer) {
                    System.out.println("⼩了");
                } else {
                    System.out.println("恭喜你！猜对拉！");
                    break;
                }
                chances = chances - 1;
            }
            System.out.println("再玩⼉⼀次吗？(y/n)");
            //接受⽤户的选择
            String again = scan.next();
 /* 将⽤户选择和字符串y⽐较（忽略⼤⼩写），如果不⼀样则结束游戏。
equalsIgnoreCase⽅法的作⽤是将调⽤字符串和参数字符串忽略⼤⼩写进⾏⽐较，相等返回
true，不等返回false */
            if (!again.equalsIgnoreCase("y")){
                break;
            }
        }
    }
}